<template>
  <div class="statistics-container">
    <div class="title">模块开关</div>
    <el-form label-width="100px">
      <el-form-item label="热门推荐模块">
        <el-switch
          v-model="label_information_status"
          @change="switInformation(label_information_status)"
        />
      </el-form-item>
      <el-form-item label="资源分类模块">
        <el-switch
          v-model="label_resource_status"
          @change="switResource(label_resource_status)"
        />
      </el-form-item>
      <el-form-item label="大咖焦点模块">
        <el-switch
          v-model="label_master_status"
          @change="switMaster(label_master_status)"
        />
      </el-form-item>
      <el-form-item label="作品分享模块">
        <el-switch
          v-model="label_works_status"
          @change="switWorks(label_works_status)"
        />
      </el-form-item>
      <el-form-item label="大薇伙伴模块">
        <el-switch
          v-model="label_cooperation_status"
          @change="switCooperation(label_cooperation_status)"
        />
      </el-form-item>
      <el-form-item label="课程培训模块">
        <el-switch
          v-model="label_curriculum_status"
          @change="switCurriculum(label_curriculum_status)"
        />
      </el-form-item>
      <el-form-item label="精选直播模块">
        <el-switch
          v-model="label_live_status"
          @change="switLive(label_live_status)"
        />
      </el-form-item>
      <el-form-item label="苹果公测结束">
        <el-switch
          v-model="apple_test_end"
          @change="switApple(apple_test_end)"
        />
      </el-form-item>
    </el-form>
    <div class="title">APP客服手机号</div>
    <div class="cont">
      <el-form :inline="true" class="demo-form-inline" label-width="130px">
        <el-form-item label="app客服手机号">
          <el-input v-model="kf_phone" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="editPhone">修改</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="title">APP版本号</div>
    <div class="cont">
      <el-form :inline="true" class="demo-form-inline" label-width="130px">
        <el-form-item label="app版本号">
          <el-input v-model="app_versions" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="editVersion">修改</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
  import { getModuleStatus, upSettings, getTestOvers } from '@/api/common'

  export default {
    name: 'Setting',
    data() {
      return {
        keys: [
          'label_information_status',
          'label_resource_status',
          'label_master_status',
          'label_works_status',
          'label_cooperation_status',
          'label_curriculum_status',
          'label_live_status',
          'apple_test_end',
          'kf_phone',
          'app_versions',
        ],
        val: '',
        label_information_status: false,
        label_resource_status: false,
        label_master_status: false,
        label_works_status: false,
        label_cooperation_status: false,
        label_curriculum_status: false,
        label_live_status: false,
        apple_test_end: false,
        app_versions: '',
        kf_phone: '',
      }
    },
    created() {
      this.getData()
    },
    methods: {
      getData() {
        let params = {
          key:
            this.keys[0] +
            ',' +
            this.keys[1] +
            ',' +
            this.keys[2] +
            ',' +
            this.keys[3] +
            ',' +
            this.keys[4] +
            ',' +
            this.keys[5] +
            ',' +
            this.keys[6] +
            ',' +
            this.keys[7] +
            ',' +
            this.keys[8] +
            ',' +
            this.keys[9],
        }
        getModuleStatus(params).then((data) => {
          this.kf_phone = data.data.kf_phone
          this.app_versions = data.data.apple_test_end
          if (data.data.label_information_status == 1) {
            this.label_information_status = true
          }
          if (data.data.label_resource_status == 1) {
            this.label_resource_status = true
          }
          if (data.data.label_master_status == 1) {
            this.label_master_status = true
          }
          if (data.data.label_works_status == 1) {
            this.label_works_status = true
          }
          if (data.data.label_cooperation_status == 1) {
            this.label_cooperation_status = true
          }
          if (data.data.label_curriculum_status == 1) {
            this.label_curriculum_status = true
          }
          if (data.data.label_live_status == 1) {
            this.label_live_status = true
          }
          if (data.data.apple_test_end == 1) {
            this.apple_test_end = true
          }
        })
      },
      switInformation(e) {
        console.log(11111, e)
        if (e == 1) {
          let params = {
            key: 'label_information_status',
            value: 1,
          }
          upSettings(params).then()
        } else {
          let params = {
            key: 'label_information_status',
            value: 2,
          }
          upSettings(params).then()
        }
      },
      switResource(e) {
        console.log(111, e)
        if (e == 1) {
          let params = {
            key: 'label_resource_status',
            value: 1,
          }
          upSettings(params).then()
        } else {
          let params = {
            key: 'label_resource_status',
            value: 2,
          }
          upSettings(params).then()
        }
      },
      switMaster(e) {
        if (e == 1) {
          let params = {
            key: 'label_master_status',
            value: 1,
          }
          upSettings(params).then()
        } else {
          let params = {
            key: 'label_master_status',
            value: 2,
          }
          upSettings(params).then()
        }
      },
      switWorks(e) {
        if (e == 1) {
          let params = {
            key: 'label_works_status',
            value: 1,
          }
          upSettings(params).then()
        } else {
          let params = {
            key: 'label_works_status',
            value: 2,
          }
          upSettings(params).then()
        }
      },
      switCooperation(e) {
        if (e == 1) {
          let params = {
            key: 'label_cooperation_status',
            value: 1,
          }
          upSettings(params).then()
        } else {
          let params = {
            key: 'label_cooperation_status',
            value: 2,
          }
          upSettings(params).then()
        }
      },
      switCurriculum(e) {
        if (e == 1) {
          let params = {
            key: 'label_curriculum_status',
            value: 1,
          }
          upSettings(params).then()
        } else {
          let params = {
            key: 'label_curriculum_status',
            value: 2,
          }
          upSettings(params).then()
        }
      },
      switLive(e) {
        if (e == 1) {
          let params = {
            key: 'label_live_status',
            value: 1,
          }
          upSettings(params).then()
        } else {
          let params = {
            key: 'label_live_status',
            value: 2,
          }
          upSettings(params).then()
        }
      },
      switApple(e) {
        if (e == 1) {
          let params = {
            key: 'apple_test_end',
            value: 1,
          }
          upSettings(params).then()
        } else {
          let params = {
            key: 'apple_test_end',
            value: 2,
          }
          upSettings(params).then()
        }
      },
      editPhone() {
        let params = {
          key: 'kf_phone',
          value: this.kf_phone,
        }
        upSettings(params).then((data) => {
          this.$message.success('修改电话成功！')
          this.getData()
        })
      },
      editVersion() {
        let params = {
          key: 'app_versions',
          value: this.app_versions,
        }
        upSettings(params).then((data) => {
          this.$message.success('修改版本号成功！')
          this.getData()
        })
      },
    },
  }
</script>

<style lang="scss" scoped>
  .title {
    margin-bottom: 20px;
    font-weight: bold;
    font-size: 18px;
  }
  .cont {
    margin-top: 20px;
  }
</style>
